import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sports_new/resources/colours.dart';
import 'package:sports_new/resources/styles.dart';
import 'package:sports_new/utils/utils.dart';

import 'qkd_text.dart';

class QkdWidget {
  static cell(String title, String detail,
      {Function()? onTap, bool isCard = true}) {
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.opaque,
      child: Styles.card(
        height: 52,
        color: Colours.white,
        padding: EdgeInsets.symmetric(horizontal: 12),
        radius: isCard ? 8 : 0,
        shadow: isCard,
        child: Row(children: [
          QkdText(title, color: Colours.text, fontSize: 16),
          const Spacer(),
          QkdText(detail, color: Colours.grey66, fontSize: 14),
          const SizedBox(width: 10),
          Image.asset(
            Utils.getImgPath("arrow_right.png"),
            width: 6,
            height: 10,
          )
        ]),
      ),
    );
  }

  //勾选框
  static selectCell(String title, bool select, {Function()? onTap}) {
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.opaque,
      child: Container(
        height: 52,
        color: Colours.white,
        padding: const EdgeInsets.symmetric(horizontal: 12),
        child: Row(children: [
          QkdText(title, color: Colours.text, fontSize: 16),
          const Spacer(),
          Image.asset(
            Utils.getImgPath(select ? 'check.png' : 'uncheck.png'),
            width: 20,
            height: 20,
          ),
        ]),
      ),
    );
  }

  static seperateLine({double indent = 12, double endIndet = 12}) {
    return Divider(
      height: 0.5,
      color: Colours.greyEE,
      indent: indent,
      endIndent: endIndet,
    );
  }

  static Widget switchCell(String title, bool select,
      {Function()? onTap, bool isCard = true}) {
    return Styles.card(
      height: 52,
      color: Colours.white,
      padding: const EdgeInsets.only(left: 12, right: 12),
      radius: isCard ? 8 : 0,
      shadow: isCard,
      child: Row(children: [
        QkdText(
          title, color: Colours.text, fontSize: 16,
        ),
        const Spacer(),
        Transform.scale(
          scale: 0.9,
          child: CupertinoSwitch(
            value: select,
            // trackColor: Colours.blue2766D6,
            activeColor: Colours.main,
            onChanged: (value) {
              if (onTap != null) {
                onTap();
              }
            },
          ),
        )
      ]),
    );
  }

  static Widget cupertinoSwitch(bool select, {Function()? onTap}) {
    return Transform.scale(
      scale: 0.9,
      child: CupertinoSwitch(
        value: select,
        // trackColor: Colours.blue2766D6,
        activeColor: Colours.main,
        onChanged: (value) {
          if (onTap != null) {
            onTap();
          }
        },
      ),
    );
  }
}
